package IOperator;

import Book.*;
import FileOperation.saveBooks;
import java.sql.SQLException;
import java.util.Scanner;
public class ReturnBooks implements IOperator {
    @Override
    public void work(Bookshelf bookshelf) throws SQLException {
        System.out.println("归还图书!");
        System.out.print("请输入你要归还的图书名字:# ");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();

        int currCount = bookshelf.getBooksNumber();
        for (int i = 0; i < currCount; i++) {
            Book book = bookshelf.getBooks(i);
            if(book.getName().equals(bookName) && book.isBorrow() == true){
                book.setBorrow(false);
                new saveBooks().fileSaveCover(bookshelf);
                System.out.println("成功归还《"+bookName+"》!");
                return;
            }
        }
        System.out.println("没有你要归还的图书!");
    }
}
